//
//  HomePageViewController.m
//  HTP
//
//  Created by 陈钱钿 on 15/11/1.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "HomePageViewController.h"
#import "RegisterOneViewController.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
@interface HomePageViewController ()
@property (nonatomic, retain) UIButton *loginBtn;
@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    
}

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBarHidden = YES;
}

//绘制UI
- (void)initUI {
    self.navigationController.navigationBarHidden = YES;
    UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeihgt)];
    bg.image = [UIImage imageNamed:@"login_bg"];
    [bg setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:bg];
    
    UIButton *closeImageView = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-50, 30, 20, 20)];
    [closeImageView setBackgroundImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    [closeImageView addTarget:self action:@selector(changeRoot) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:closeImageView];
    
    UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((ScreenWidth-180)/2, ScreenHeihgt/6, 180, 50)];
    logoImageView.image = [UIImage imageNamed:@"logo"];
    [self.view addSubview:logoImageView];
    
    self.loginBtn = [[UIButton alloc] initWithFrame:CGRectMake((ScreenWidth-220)/2, ScreenHeihgt/2+40, 220, 40)];
    [self.loginBtn setBackgroundImage:[UIImage imageNamed:@"login"] forState:UIControlStateNormal];
    [self.loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.loginBtn];
    
    UIButton *regBtn = [[UIButton alloc] initWithFrame:CGRectMake((ScreenWidth-220)/2, CGRectGetMaxY(self.loginBtn.frame)+20, 220, 40)];
    [regBtn setBackgroundImage:[UIImage imageNamed:@"reg"] forState:UIControlStateNormal];
    [regBtn addTarget:self action:@selector(regClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:regBtn];
}

/*
 点击注册
 */
- (void)regClick {
    DLog(@"点击注册");
    RegisterOneViewController *oneVc = [[RegisterOneViewController alloc] init];
    [self.navigationController pushViewController:oneVc animated:YES];
}

/*
 点击登录
 */
- (void)login {
    LoginViewController *loginVc = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:loginVc animated:YES];
//    [self changeRoot];
}

/*
更改RootViewController
 */
-(void)changeRoot{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [app changeRootVc];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
